package com.fenqing.leetcode.code.t200_300;

import com.fenqing.annotations.DesignClass;
import com.fenqing.core.design.DesignTopic;

import java.util.Stack;

public class Topic232 extends DesignTopic {

    public Topic232() {
        super(
                """
                        ["MyQueue", "push", "push", "peek", "pop", "empty"]
                        """, """
                        [[], [1], [2], [], [], []]
                        """);
    }

    @DesignClass
    public static class MyQueue {

        Stack<Integer> stack1, stack2;

        public MyQueue() {
            stack1 = new Stack<>();
            stack2 = new Stack<>();
        }

        public void push(int x) {
            stack1.push(x);
        }

        private void transfer(){
            if (stack2.isEmpty()) {
                while (!stack1.isEmpty()) {
                    stack2.push(stack1.pop());
                }
            }
        }

        public int pop() {
            transfer();
            return stack2.pop();
        }

        public int peek() {
            transfer();
            return stack2.peek();
        }

        public boolean empty() {
            transfer();
            return stack2.isEmpty();
        }
    }

    public static void main(String[] args) {
        System.out.println(new Topic232().run());
    }

}
